import { Controller, Post, Res, UploadedFile, UseInterceptors } from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import { Express, Response } from "express";
import { hostUrl } from "../../utils/hostUrl";

@Controller("/upload")
export class UploadController {
  @Post("/file")
  @UseInterceptors(FileInterceptor("file"))
  uploadFile(@UploadedFile() file: Express.Multer.File, @Res() res: Response) {
    res.json({
      status: "success",
      message: "文件上传成功！",
      url: hostUrl(file.filename)
    });
  }
}
